<?php

/**
 * This is the model class for table "preco".
 *
 * The followings are the available columns in table 'preco':
 * @property integer $id
 * @property string $zona_id
 * @property integer $tabuleiro_id
 * @property string $menor_igual_um
 * @property string $entre_dois_cinco
 * @property string $mais_de_cinco
 * @property string $created_at
 * @property string $updated_at
 * @property string $id_produto
 *
 * The followings are the available model relations:
 * @property Tabuleiro $tabuleiro
 */
class Preco extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Preco the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'preco';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('zona_id, tabuleiro_id, menor_igual_um, entre_dois_cinco, mais_de_cinco, id_produto', 'required'),
            array('tabuleiro_id', 'numerical', 'integerOnly' => true),
            array('zona_id, menor_igual_um, entre_dois_cinco, mais_de_cinco', 'length', 'max' => 10),
            array('id_produto', 'length', 'max' => 11),
            array('created_at, updated_at', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, zona_id, tabuleiro_id, menor_igual_um, entre_dois_cinco, mais_de_cinco, created_at, updated_at, id_produto', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'tabuleiro' => array(self::BELONGS_TO, 'Tabuleiro', 'tabuleiro_id'),
            'produtos' => array(self::MANY_MANY, 'Produto', 'produto_preco(preco_id,produto_id)'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'zona_id' => 'Zona',
            'tabuleiro_id' => 'Tabuleiro',
            'menor_igual_um' => 'Menor Igual Um',
            'entre_dois_cinco' => 'Entre Dois Cinco',
            'mais_de_cinco' => 'Mais De Cinco',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
            'id_produto' => 'Id Produto',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('zona_id', $this->zona_id, true);
        $criteria->compare('tabuleiro_id', $this->tabuleiro_id);
        $criteria->compare('menor_igual_um', $this->menor_igual_um, true);
        $criteria->compare('entre_dois_cinco', $this->entre_dois_cinco, true);
        $criteria->compare('mais_de_cinco', $this->mais_de_cinco, true);
        $criteria->compare('created_at', $this->created_at, true);
        $criteria->compare('updated_at', $this->updated_at, true);
        $criteria->compare('id_produto', $this->id_produto, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}
